var app = getApp();
const util = require('../../utils/util.js');
Page({

  /**
   * 
   * 页面的初始数据
   */
  data: {
    actionNav:0,
    screenHeight:0,
    current:0,
    dfh:[],
    dsh:[],
    ywc:[],
    currentPage:1,
    isxia:false,
    orderData:[]
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var that = this;
    var currentTab = options.currentTab;
    // debugger
    // console.log(currentTab)
    wx.getSystemInfo({
      success: function(res) {
        that.setData({
          screenHeight: res.screenHeight,
          actionNav: currentTab,
          current: currentTab
        })
      },
    })
    // this.initData();
  },
  selNav:function(e){
    var index = e.currentTarget.dataset.index;
    this.setData({
      actionNav: index,
      current:index,
      orderData:[]
    })
    this.initData();
  },
  swiperFinsh:function(e){
    var index = e.detail.current;
    this.setData({
      actionNav: index
    })
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
    
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    this.initData();
  },
  initData:function(){
    var that = this;
    var data = {
       userid: app.globalData.userInfo.id, 
       status: that.data.current,
       currentPage:that.data.currentPage
    };
    util.commonRequest("index/Order/orderlist",'post', data, function (res) {
      wx.stopPullDownRefresh();
      if (res.data.code == 200){
        // let tempData = res.data.data.data;
        // if (that.data.isxia)
        // {
        //   that.setData({
        //     orderData:tempData,
        //     currentPage:1,
        //     last_page: res.data.data.last_page
        //   })
        //   return;
        // }
        let tempArr = res.data.data.data;
        let oldData = that.data.orderData;
        // debugger
        let finallyData = oldData.concat(tempArr);
        that.setData({
          orderData: finallyData,
          last_page: res.data.data.last_page
        })
      }
    });
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
    
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
    
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
    this.setData({orderData:[],currentPage:1})
    this.initData();
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    let currentPage = this.data.currentPage;
    let data = this.data.orderData;
    let last_page = this.data.last_page;
    if (currentPage < last_page) {
      this.setData({
        currentPage: currentPage + 1,
        isxia: false
      })
      this.initData();
    }
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
    
  }
})